package com.atm.servlet;

import com.atm.pojo.User;
import com.atm.service.UserService;
import com.atm.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 查询用户余额
 */
@WebServlet("/UserSerch")
public class UserSerchServlet extends HttpServlet {
    private UserService userService = new UserServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String icno = null;
        if (req.getSession().getAttribute("ua")!=null){
            User user=(User)req.getSession().getAttribute("ua");
             icno = user.getIcno();
        }
        double balance = userService.getUserBalance(icno);
        req.getSession().setAttribute("balance", balance);
//        req.getRequestDispatcher("/changepage/SerchBalance.jsp").forward(req,resp);
        resp.sendRedirect("/changepage/SerchBalance.jsp");
    }
}
